package com.aishua.andpaydemo.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;

import com.aishua.andpaydemo.R;
import com.aishua.andpaydemo.utils.TableLayoutChangeColorUtils;

/**
 * Created by aishua on 2018/5/17.
 */

public class XingquAdapter extends RecyclerView.Adapter<XingquAdapter.MyDeviceViewHoler>  {
    private static final String TAG = "HomeHotAdapter-";

    private String[] xignquname;
    private Context mContext;


    public XingquAdapter(Context mContext, String[] xignquname) {

        this.mContext = mContext;
        this.xignquname = xignquname;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public XingquAdapter.MyDeviceViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(mContext, R.layout.item_faxian_xingqu, null);
        XingquAdapter.MyDeviceViewHoler holder = new XingquAdapter.MyDeviceViewHoler(view);
        return holder;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindViewHolder(XingquAdapter.MyDeviceViewHoler holder, final int position) {

        holder.displayView(position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onRecycleViewClickListener.onRecycleViewClick(position);
            }
        });

    }

    @Override
    public int getItemCount() {

        return xignquname.length;
    }


    public class MyDeviceViewHoler extends RecyclerView.ViewHolder {

        private Button rb_faxian_xingqu;

        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        public MyDeviceViewHoler(View itemView) {

            super(itemView);
            rb_faxian_xingqu = itemView.findViewById(R.id.rb_faxian_xingqu);
            int clolrID = TableLayoutChangeColorUtils.getThemeColorId(mContext);
            rb_faxian_xingqu.setBackground(mContext.getDrawable(clolrID));

        }

        @RequiresApi(api = Build.VERSION_CODES.M)
        public void displayView(int position) {

            rb_faxian_xingqu.setText(xignquname[position]);

        }

    }

    public void setonRecycleViewClickListener(HomeHotAdapter.onRecycleViewClickListener onRccycleViewLongClickListener) {
        this.onRecycleViewClickListener = onRccycleViewLongClickListener;
    }

    private HomeHotAdapter.onRecycleViewClickListener onRecycleViewClickListener;

    public interface onRecycleViewClickListener {

        public void onRecycleViewClick(int position);

    }
}
